<template>
  <div class="box">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item class="q1" label="账号">
        <el-input
          type="text"
          placeholder="请输入账号"
          v-model="form.name"
        ></el-input>
      </el-form-item>
      <el-form-item class="q1" label="密码">
        <el-input
          type="password"
          placeholder="请输入密码"
          v-model="form.pass"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="btn" @click="login">登录</el-button>
        <el-button class="btn1" @click="chong">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
        pass: "",
      },
    };
  },
  methods: {
    // 登录
    login() {
      this.$axios
        .post("http://ceshi5.dishait.cn/admin/login", {
          username: this.form.name,
          password: this.form.pass,
        })
        .then((res) => {
          localStorage.setItem("token", res.data.data.token);
          this.$router.push({ path: "/home" });
          this.$message({
            message: "恭喜你登录成功",
            type: "success",
          });
        })
         .catch((res) => {
          this.$message({
            showClose: true,
            message: "账号密码错误",
            type: "error",
          });
        });
    },
    // 重置
    chong() {
      (this.form.name = ""), (this.form.pass = "");
    },
  },
};
</script>
<style  scoped>
.box {
  width: 500px;
  height: 300px;
  background: rgb(0, 255, 217);
  margin: 0 auto;
  margin-top: 200px;
  padding-top: 0.1px;
}
.q1 {
  width: 460px;
  margin-top: 60px;
  margin-left: -10px;
}
.btn {
  margin-left: -10px;
  margin-top: 16px;
}
.btn1 {
  margin-left: 20px;
}
</style>